Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
driver_MAG3110.c File Reference
+ Include dependency graph for driver_MAG3110.c:

Go to the source code of this file.

Macros

#define MAG3110_COUNTSPERUT   10
 

Functions

int8_t MAG3110_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MAG3110_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MAG3110_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 

Variables

const registerreadlist_t MAG3110_WHO_AM_I_READ []
 
const registerreadlist_t MAG3110_DR_STATUS_READ []
 
registerreadlist_t MAG3110_DATA_READ []
 
const registerwritelist_t MAG3110_Initialization []
 
const registerwritelist_t MAG3110_IDLE []
 

Macro Definition Documentation

#define MAG3110_COUNTSPERUT   10

Definition at line 40 of file driver_MAG3110.c.

Referenced by MAG3110_Init().

Function Documentation

int8_t MAG3110_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 168 of file driver_MAG3110.c.

Referenced by fusion_task().

169 {
170  int32_t status;
171  if(sensor->isInitialized == F_USING_MAG) {
172  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, MAG3110_IDLE );
173  sensor->isInitialized = 0;
174  sfg->Mag.isEnabled = false;
175  } else {
176  return SENSOR_ERROR_INIT;
177  }
178  return status;
179 }
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
MagSensor Mag
magnetometer storage
const registerwritelist_t MAG3110_IDLE[]
bool isEnabled
true if the device is sampling
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the caller graph for this function:

int8_t MAG3110_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 103 of file driver_MAG3110.c.

Referenced by fusion_task(), and main().

104 {
105  int32_t status;
106  uint8_t reg;
107  status = Register_I2C_Read(sensor->bus_driver, sensor->addr, MAG3110_WHO_AM_I, 1, &reg);
108  if (status==SENSOR_ERROR_NONE) {
109  sfg->Mag.iWhoAmI = reg;
110  if (reg!=MAG3110_WHOAMI_VALUE) {
111  return(SENSOR_ERROR_INIT);
112  }
113  } else {
114  // iWhoAmI will return default value of zero
115  // return with error
116  return(SENSOR_ERROR_INIT);
117  }
118 
119  // Configure and start the MAG3110 sensor. This does multiple register writes
120  // (see MAG3110_Initialization definition above)
121  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, MAG3110_Initialization );
122 
123  // Stash some needed constants in the SF data structure for this sensor
125  sfg->Mag.fCountsPeruT = (float)MAG3110_COUNTSPERUT; // IAR optimized this out without the #pragma before the function
126  sfg->Mag.fuTPerCount = 1.0F / MAG3110_COUNTSPERUT; // IAR optimized this out without the #pragma before the function
127 
128  sensor->isInitialized = F_USING_MAG; // IAR optimized this out without the #pragma before the function
129  sfg->Mag.isEnabled = true; // IAR optimized this out without the #pragma before the function
130 
131  return (status);
132 }
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
int16_t iCountsPeruT
counts per uT
MagSensor Mag
magnetometer storage
float fuTPerCount
uT per count
bool isEnabled
true if the device is sampling
float fCountsPeruT
counts per uT
const registerwritelist_t MAG3110_Initialization[]
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define MAG3110_COUNTSPERUT
uint8_t iWhoAmI
sensor whoami
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the caller graph for this function:

int8_t MAG3110_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 134 of file driver_MAG3110.c.

Referenced by main().

135 {
136  uint8_t I2C_Buffer[6]; // I2C read buffer
137  int8_t status; // I2C transaction status
138  int16_t sample[3]; // Reconstructed sample
139 
140  if(sensor->isInitialized != F_USING_MAG)
141  {
142  return SENSOR_ERROR_INIT;
143  }
144 
145  status = Sensor_I2C_Read(sensor->bus_driver, sensor->addr, MAG3110_DATA_READ, I2C_Buffer );
146  sample[CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
147  sample[CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
148  sample[CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
149  if (status==SENSOR_ERROR_NONE) {
150  conditionSample(sample); // truncate negative values to -32767
151  sample[CHZ] = -sample[CHZ]; // +Z should point up (MAG3110 Z positive is down)
152  addToFifo((FifoSensor*) &(sfg->Mag), MAG_FIFO_SIZE, sample);
153  }
154 
155  return (status);
156 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
MagSensor Mag
magnetometer storage
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
#define CHZ
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two&#39;s complement value for a 16-...
registerreadlist_t MAG3110_DATA_READ[]
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

registerreadlist_t MAG3110_DATA_READ[]
Initial value:
=
{
{ .readFrom = MAG3110_OUT_X_MSB, .numBytes = 6 }, __END_READ_DATA__
}

Definition at line 57 of file driver_MAG3110.c.

Referenced by MAG3110_Read().

const registerreadlist_t MAG3110_DR_STATUS_READ[]
Initial value:
=
{
{ .readFrom = MAG3110_DR_STATUS, .numBytes = 1 }, __END_READ_DATA__
}

Definition at line 51 of file driver_MAG3110.c.

const registerwritelist_t MAG3110_IDLE[]
Initial value:
=
{
{ MAG3110_CTRL_REG1, 0x00, 0x00 },
__END_WRITE_DATA__
}

Definition at line 160 of file driver_MAG3110.c.

Referenced by MAG3110_Idle().

const registerwritelist_t MAG3110_Initialization[]

Definition at line 63 of file driver_MAG3110.c.

Referenced by MAG3110_Init().

const registerreadlist_t MAG3110_WHO_AM_I_READ[]
Initial value:
=
{
{ .readFrom = MAG3110_WHO_AM_I, .numBytes = 1 }, __END_READ_DATA__
}

Definition at line 45 of file driver_MAG3110.c.